﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApplication3.权限管理
{
    public partial class addStudents : Form
    {            
        public addStudents()
        {
            InitializeComponent();
        }
        //“确定”按键
        private void buttonOk_Click(object sender, EventArgs e)
        {
            try
            {
                string myStudentsID = addStudents_ID.Text.Trim(); //学生ID

                DataSet ds = 权限管理.permissionManaging.mySql.sql_search_database("select * from studentstable "
                    + "where studentsID= '" + myStudentsID + "' ");
                int rowcount = ds.Tables[0].Rows.Count;
                if (rowcount != 0) { MessageBox.Show("ID  have existed"); return; };

                string myStudentsName = addStudents_name.Text.Trim(); //学生名字
                string myStudnetsPasswd = addStudents_passwd.Text.Trim();//学生密码
                string myStudentsPressions = addStudents_pressions.Text.Trim(); //权限
                string myStudentsDepartments = addStudents_departments.Text.Trim();//院系
                string myStudentsClasses = addStudents_classes.Text.Trim();// 班级

                if (myStudentsID == "") { MessageBox.Show("学生ID不能为空！"); return; }
                if (myStudentsName == "") { MessageBox.Show("学生姓名不能为空！"); return; }
                if (myStudnetsPasswd == "") { MessageBox.Show("学生密码不能为空！"); return; }
                if (myStudentsPressions == "") { MessageBox.Show("学生权限不能为空！"); return; }
                if (myStudentsDepartments == "") { MessageBox.Show("学生院系不能为空！"); return; }
                if (myStudentsClasses == "") { MessageBox.Show("学生班级不能为空！"); return; }
                //插入数据库
                权限管理.permissionManaging.mySql.excute_sql("insert into studentstable values ('"
                    + myStudentsID   +"','"
                    + myStudentsName +"','"
                    + myStudnetsPasswd + "','"
                    + myStudentsPressions + "','"
                    + myStudentsDepartments + "','"
                    + myStudentsClasses +"')" );
                权限管理.permissionManaging.mySql.excute_sql("insert into sqlTableName_and_IDtable values ('"
                    + myStudentsID + "','"
                    + "studentstable" + "')");
                //Debug.WriteLine("insert into sqlTableName_and_IDtable values ('"
                //    + myStudentsID + "','"
                //    + "studentstable" + "')");
                //传递给permissionManaging 学生ID     
                权限管理.permissionManaging.addStudentsInfo_ID = myStudentsID;
                

                this.Dispose();
            }
            catch
            {
                MessageBox.Show("添加过程中出现错误！");
            }
        }
        //“取消”按键
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
